package com.mastercard.assets.web.struts.actions;

import com.mastercard.assets.MasterCardException;
import com.mastercard.assets.jpa.TblDomestic;
import com.mastercard.assets.util.dao.MasterCardDAO;
import com.mastercard.assets.web.util.to.UserLogin;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class CalcularListaMenuCm 
        extends
		Action
{
        public ActionForward execute(
							ActionMapping mapping , 
							ActionForm form ,
							HttpServletRequest request , 
							HttpServletResponse response )
		throws 
			IOException , 
			ServletException
        {
            HttpSession session = request.getSession( ) ;
		
		// en caos de null
		if( session == null )
			return mapping.findForward( "noLogin" ) ;
		
		// toma el userLogin
		UserLogin user = ( UserLogin ) session.getAttribute( "UserLogin" ) ;
		
		// en caso de null
		if( user == null )
			return mapping.findForward( "noLogin" ) ;
                
//                double x , y ;
//                String X , Y ;
                
                
		
		try
		{
			// en caso de que se cumpla
			// calcula los tipos de cuentas existentes.
                    List< TblDomestic > Dbps = MasterCardDAO.findAllActiveBps( ) ;
                    for ( TblDomestic d : Dbps ) {
//                        X = ""+d.getDomesticBps() ;
//                        x = Double.parseDouble( X )  ;
                        System.err.println( ":::"+d.getCveDomestic()+" - "+d.getDomesticBps()+" - "+d.getIntlBps()+" - "+d.getCardBps()+" - "+d.getPercentDomestic()+" - "+d.getTblCuenta().getNombre()+" - "+d.getTblProducto().getNombre()+" - "+d.getStatus() );
                    }
                    
			request.setAttribute( "ActiveUsers" , MasterCardDAO.findAllActiveBps( )  ) ;
			
		}catch( MasterCardException e )
		{
                    MasterCardDAO.closeEntityManager( ) ;
			user.setMessageError( e.getMessage( ) ) ;
		}
		
                MasterCardDAO.closeEntityManager( ) ;
	  	return mapping.findForward( "success" ) ;
        }
}
